<!-- 设备管理-设备列表页面 -->
<template>
  <div class="app-container">
    <px-form v-show="showSearch" ref="queryRef" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
      <px-form-item label="设施/活动名称">
        <px-input v-model="queryParams.name" placeholder="请输入" clearable />
      </px-form-item>
      <px-form-item label="设施/活动类别">
        <px-select v-model="queryParams.category" placeholder="请选择" clearable style="width: 240px" filterable>
          <px-option v-for="dict in liquidList" :key="dict.id" :label="dict.itemName" :value="dict.itemName" />
        </px-select>
      </px-form-item>
      <px-form-item label="排放因子名称">
        <px-input v-model="queryParams.emissionFactorName" placeholder="请输入" clearable />
      </px-form-item>
      <!-- <px-form-item label="所属厂区">
        <px-select v-model="queryParams.level" placeholder="请选择" clearable filterable>
          <px-option v-for="item in facList" :key="item.itemName" :label="item.itemName" :value="item.itemValue" />
        </px-select>
      </px-form-item> -->
      <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery('search')">搜索</px-button>
      <px-button style="margin-top: -17px" icon="" @click="resetQuery">重置</px-button>
    </px-form>

    <px-row :gutter="10" class="mb8">
      <px-col :span="1.5">
        <px-button v-has="'ACCOUNTINGLIST_ADD'" type="primary" icon="" @click="handleAdd">新增</px-button>
      </px-col>
      <px-col :span="1.5">
        <px-button v-has="'ACCOUNTINGLIST_INTO'" type="primary" plain icon="" @click="handleImport">导入</px-button>
      </px-col>
      <px-col :span="1.5">
        <px-button v-has="'ACCOUNTINGLIST_EXPORT'" type="primary" plain icon="" @click="handleExport">导出</px-button>
      </px-col>
    </px-row>
    <px-dialog v-model="dialogVisible" title="导入数据" :width="600">
      <div class="import-bottle">
        <div class="import-bottle-title">
          上传前请先
          <span class="download" @click="handleDown(equipdata.reportId, equipdata.templateId)"> 下载模板 </span>
          ，填写完成后导入数据
        </div>
        <div class="import-bottle-upload">
          <importFiles v-model="importFile" :uploadApi="facilityuploadFile" @submit="submitHandler" />
        </div>
      </div>
    </px-dialog>
    <px-table v-if="!addVisible && !detailVisible" v-loading="loading" :data="typeList" height="calc(100vh - 319px)" border>
      <px-table-column label="序号" fixed="left" type="index" width="70">
        <template #default="{ $index }">
          {{ $index + 1 + (queryParams.pageNum - 1) * queryParams.pageSize }}
        </template>
      </px-table-column>
      <px-table-column width="280" label="设施/活动名称" prop="name">
        <template #default="scope">
          <span>{{ scope.row.name }}</span>
        </template>
      </px-table-column>

      <!-- <px-table-column width="140" label="所属厂区" prop="level">
        <template #default="scope">
          <span>{{ scope.row.level }}</span>
        </template>
      </px-table-column> -->

      <px-table-column width="110" label="设施活动编号" prop="serialNumber">
        <template #default="scope">
          <span>{{ scope.row.serialNumber }}</span>
        </template>
      </px-table-column>

      <px-table-column label="设施/活动类别" width="160" prop="category">
        <template #default="scope">
          <span>{{ scope.row.category }}</span>
        </template>
      </px-table-column>

      <px-table-column width="180" label="关联能源指标" prop="relatedEnergyName">
        <template #default="scope">
          <span>{{ scope.row.relatedEnergyName }}</span>
        </template>
      </px-table-column>
      <!-- <px-table-column width="120" label="所属核算边界" prop="boundaryName">
        <template #default="scope">
          <span>{{ scope.row.boundaryName.length > 0 ? scope.row.boundaryName : "-" }}</span>
        </template>
      </px-table-column> -->

      <px-table-column width="120" label="活动水平单位" prop="activityLevelUnit">
        <template #default="scope">
          <span>{{ scope.row.activityLevelUnit }}</span>
        </template>
      </px-table-column>
      <px-table-column width="116" label="单位换算比例" prop="unitConversionRatio">
        <template #default="scope">
          <span>{{ scope.row.unitConversionRatio }}</span>
        </template>
      </px-table-column>
      <px-table-column width="220" label="排放因子名称" prop="emissionFactorName">
        <template #default="scope">
          <span>{{ scope.row.emissionFactorName }}</span>
        </template>
      </px-table-column>
      <px-table-column width="120" label="排放因子" prop="emissionFactorValue">
        <template #default="scope">
          <span>{{ scope.row.emissionFactorValue }} {{ scope.row.moleculeUnit }}/{{ scope.row.denominatorUnit }}</span>
        </template>
      </px-table-column>
      <px-table-column width="80" label="发布年份" prop="releaseYear">
        <template #default="scope">
          <span>{{ scope.row.releaseYear }}</span>
        </template>
      </px-table-column>
      <px-table-column width="150" label="来源文件">
        <template #default="scope">
          <span
            v-for="button in scope.row.fileDTOS"
            :key="button.id"
            style="width: 600px; color: #3b82f6; text-align: left; cursor: pointer"
            @click="handleFileBrowsedetail(button)"
            >{{ button.originalName }}</span
          >
        </template>
      </px-table-column>
      <px-table-column label="创建人" width="110" prop="createByName">
        <template #default="scope">
          <span>{{ scope.row.createByName }}</span>
        </template>
      </px-table-column>
      <px-table-column label="创建时间" width="170" prop="createTime">
        <template #default="scope">
          <span>{{ scope.row.createTime }}</span>
        </template>
      </px-table-column>

      <px-table-column label="修改人" width="110" prop="updateByName">
        <template #default="scope">
          <span>{{ scope.row.updateByName }}</span>
        </template>
      </px-table-column>
      <px-table-column width="170" label="修改时间" prop="updateTime">
        <template #default="scope">
          <span>{{ scope.row.updateTime }}</span>
        </template>
      </px-table-column>
      <px-table-column fixed="right" label="操作" align="center" width="140">
        <template #default="scope">
          <px-button v-has="'ACCOUNTINGLIST_DETAIL'" link type="primary" @click="handleDetail(scope.row.id)">
            <px-tooltip class="box-item" content="详情" placement="top">
              <px-icon>
                <Tickets />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button v-if="scope.row.status != 'INVALID'" v-has="'ACCOUNTINGLIST_EDITOR'" link type="primary" @click="handleEditor(scope.row.id)">
            <px-tooltip class="box-item" content="编辑" placement="top">
              <px-icon>
                <EditPen />
              </px-icon> </px-tooltip
          ></px-button>
          <px-button v-if="scope.row.status != 'INVALID'" v-has="'ACCOUNTINGLIST_DELETE'" link type="danger" @click="handleDelete(scope.row)"
            ><px-tooltip class="box-item" content="删除" placement="top">
              <px-icon>
                <Delete />
              </px-icon> </px-tooltip
          ></px-button>
        </template>
      </px-table-column>
      <template #empty>
        <px-empty :image-size="150" />
      </template>
    </px-table>

    <pagination
      v-if="!equipopen && !equipopenDetail"
      v-show="total > 0"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      style="margin-bottom: -10px"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改参数配置对话框 -->
    <px-dialog v-model="innerVisible" width="1372" title="排放因子库" append-to-body align-center>
      <px-form v-show="showSearch" class="custom-form-ui" :model="queryParams" :inline="true" label-width="90px">
        <px-form-item label="排放因子名称">
          <px-input v-model="queryParams2.emissionFactorName" :maxlength="100" placeholder="请输入排放因子名称" clearable />
        </px-form-item>
        <px-form-item label="排放因子来源">
          <px-select v-model="queryParams2.factorSource" placeholder="请选择" clearable style="width: 240px" filterable>
            <px-option v-for="dict in SourceList" :key="dict.itemName" :label="dict.itemName" :value="dict.itemName" />
          </px-select>
        </px-form-item>
        <!-- <px-form-item label="年份">
          <px-date-picker v-model="queryParams2.releaseYear" type="year" value-format="YYYY" placeholder="请选择年份" />
        </px-form-item> -->
        <px-button style="margin-top: -17px" type="primary" icon="" @click="handleQuery2('search')">搜索</px-button>
        <px-button style="margin-top: -17px" icon="" @click="resetQuery2">重置</px-button>
      </px-form>
      <px-table
        v-loading="loading"
        :data="rukuList"
        height="calc(100vh - 339px)"
        show-overflow-tooltip
        highlight-current-row
        border
        @current-change="handleSelectionChange2"
      >
        <!-- <px-table-column type="selection" width="40" /> -->
        <px-table-column label="" width="40">
          <template #default="scope">
            <span>
              <px-radio v-model="selectrow" :label="scope.row" size="large" @change="handelRadio(scope.row)">{{
                scope.row.xx ? scope.row.xx : " "
              }}</px-radio></span
            >
          </template>
        </px-table-column>
        <px-table-column label="排放因子名称" width="160" prop="inboundNumber">
          <template #default="scope">
            <span>{{ scope.row.name }}</span>
          </template>
        </px-table-column>
        <px-table-column label="产生的GHG种类" prop="gasType">
          <template #default="scope">
            <span>{{ scope.row.gasType }}</span>
          </template>
        </px-table-column>
        <px-table-column label="CO₂e排放因子" prop="value">
          <template #default="scope">
            <span>{{ scope.row.value }}</span>
          </template>
        </px-table-column>
        <px-table-column label="CO₂e排放因子单位" prop="unit">
          <template #default="scope">
            <span>{{ scope.row.unit ? scope.row.unit : "-" }}{{ scope.row.wasteUnit }}</span>
          </template>
        </px-table-column>
        <px-table-column label="排放因子来源" prop="factorSource">
          <template #default="scope">
            <span>{{ scope.row.factorSource ? scope.row.factorSource : "-" }}{{ scope.row.wasteUnit }}</span>
          </template>
        </px-table-column>
        <!-- <px-table-column label="发布年份" prop="releaseYear">
          <template #default="scope">
            <span>{{ scope.row.releaseYear }}</span>
          </template>
        </px-table-column> -->
        <template #empty>
          <px-empty :image-size="150" />
        </template>
      </px-table>

      <pagination
        v-show="total2 > 0"
        v-model:page="queryParams2.pageNum"
        v-model:limit="queryParams2.pageSize"
        style="margin-bottom: -10px"
        :total="total2"
        @pagination="getRukuList"
      />
      <template #footer>
        <span class="dialog-footer">
          <px-button @click="innerVisible = false">取消</px-button>
          <px-button type="primary" @click="saveYinziku()"> 确定 </px-button>
        </span>
      </template>
    </px-dialog>
    <px-scrollbar v-if="addVisible" class="addEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="equipopenDetailcancel">返回</px-button>
      <px-form
        ref="detailruleFormRef"
        :disabled="fromdisable"
        :rules="rules"
        :model="equipdata"
        :inline="true"
        class="demo-form-inline"
        label-width="160px"
      >
        <div
          class="box-card1"
          :style="{
            height: jibenxinxiFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setqingdanFlg()">
            <div class="card-title">设施/活动信息</div>
            <div class="card-main">
              <px-icon v-if="!jibenxinxiFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="设施/活动名称" prop="name">
                  <px-input v-model="equipdata.name" :maxlength="100" placeholder="请输入" clearable />
                </px-form-item>
              </px-col>
              <!-- <px-col :span="12">
                <px-form-item label="所属厂区" prop="level">
                  <px-select v-model="equipdata.level" style="width: calc(100% - 70px)" placeholder="请选择" clearable filterable>
                    <px-option v-for="item in facList2" :key="item.itemName" :label="item.itemName" :value="item.itemValue" />
                  </px-select>
                </px-form-item>
              </px-col> -->
              <px-col :span="12">
                <px-form-item label="设施活动编号" prop="serialNumber">
                  <px-input v-model="equipdata.serialNumber" :maxlength="10" placeholder="请输入" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="设施/活动类别" prop="category">
                  <px-select v-model="equipdata.category" :maxlength="100" placeholder="请选择" clearable style="width: calc(100% - 70px)" filterable>
                    <px-option v-for="dict in liquidList" :key="dict.id" :label="dict.itemName" :value="dict.itemName" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="活动水平单位" prop="activityLevelUnit">
                  <px-select
                    v-model="equipdata.activityLevelUnit"
                    placeholder="请选择"
                    clearable
                    style="width: calc(100% - 70px)"
                    filterable
                    @change="val => getUnitConvert(val, equipdata.unit)"
                  >
                    <px-option v-for="dict in levelUnitList" :key="dict.id" :label="dict.itemName" :value="dict.itemName" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="能源指标">
                  <!-- <px-select v-model="equipdata.relatedEnergy" placeholder="请选择" clearable style="width: calc(100% - 70px)" filterable>
                    <px-option v-for="dict in energyList" :key="dict.id" :label="dict.itemName" :value="dict.itemName" />
                  </px-select> -->
                  <div style="width: calc(100% - 70px)">
                    <px-tree-select
                      v-model="equipdata.relatedEnergy"
                      style="width: 100%"
                      placeholder="请选择"
                      :props="defaultProps"
                      :data="codeList"
                      :render-after-expand="false"
                    />
                  </div>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子名称" prop="emissionFactorName">
                  <px-input v-model="equipdata.emissionFactorName" disabled placeholder="自动带出" clearable />
                  <px-button style="margin-left: 8px" type="primary" plain @click="selectyinzi()">选择</px-button>
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子发布年份" prop="releaseYear">
                  <px-input v-model="equipdata.releaseYear" disabled placeholder="自动带出" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子数值" prop="value">
                  <px-input v-model="equipdata.value" disabled placeholder="自动带出" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子来源" prop="factorSource">
                  <px-input v-model="equipdata.factorSource" disabled placeholder="自动带出" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="排放因子单位" prop="unit">
                  <px-input v-model="equipdata.unit" disabled placeholder="自动带出" clearable />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="单位转换比例" prop="unitConversionRatio">
                  <px-input-number
                    v-model="equipdata.unitConversionRatio"
                    :min="0"
                    :max="99999.99999"
                    controls-position="right"
                    :precision="5"
                    style="width: calc(100% - 70px)"
                    placeholder="请输入"
                    clearable
                  />
                  <px-tooltip class="box-item" effect="dark" content="活动数据单位/排放因子分母单位" placement="top">
                    <px-icon style="margin-left: 8px; cursor: pointer">
                      <QuestionFilled color="#3B82F6" />
                    </px-icon>
                  </px-tooltip>
                </px-form-item>
              </px-col>
            </px-row>
            <!-- <px-row>
              <px-col :span="12">
                <px-form-item label="排放类别" prop="emissionCategory">
                  <px-tree-select
                    v-model="equipdata.emissionCategory"
                    placeholder="请选择"
                    :props="defaultProps"
                    style="width: calc(100% - 70px)"
                    :data="categoryTypeList"
                    :render-after-expand="false"
                  />
                </px-form-item>
              </px-col>
            </px-row> -->
          </div>
        </div>

        <div
          class="box-card2"
          :style="{
            height: zhibiaoFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setzhibiaoFlg()">
            <div class="card-title">碳排放源月平均排放标准值设置</div>
            <div class="card-main">
              <px-icon v-if="!zhibiaoFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="目标值（tCO₂e）">
                  <px-input-number
                    v-model="equipdata.targetValue"
                    style="width: calc(100% - 70px)"
                    controls-position="right"
                    :max="99999999"
                    :precision="5"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
              <px-col :span="12">
                <px-form-item label="标杆值（tCO₂e）">
                  <px-input-number
                    v-model="equipdata.benchmarkValue"
                    style="width: calc(100% - 70px)"
                    controls-position="right"
                    :max="99999999"
                    :precision="5"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
            </px-row>
            <px-row>
              <px-col :span="12">
                <px-form-item label="合规值（tCO₂e）">
                  <px-input-number
                    v-model="equipdata.complianceValue"
                    style="width: calc(100% - 70px)"
                    controls-position="right"
                    :max="99999999"
                    :precision="5"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
            </px-row>
          </div>
        </div>
        <div
          v-if="equipdata.relatedEnergy != ''"
          class="box-card2"
          style="margin-bottom: 50px"
          :style="{
            height: jiqicanshuFlg == true ? '' : '42px'
          }"
        >
          <div class="card-header" @click="setjiqicanshuFlg()">
            <div class="card-title">指标设置</div>
            <div class="card-main">
              <px-icon v-if="!jiqicanshuFlg">
                <ArrowDown />
              </px-icon>
              <px-icon v-else>
                <ArrowUp />
              </px-icon>
            </div>
          </div>
          <div class="form-div">
            <px-row>
              <px-col :span="12">
                <px-form-item label="自动创建指标" prop="limitMethod">
                  <px-radio-group v-model="zhibiaostatus" :disabled="buttonTitle == '编辑'" class="ml-4">
                    <px-radio label="否" size="large">否</px-radio>
                    <px-radio label="是" size="large">是</px-radio>
                  </px-radio-group>
                </px-form-item>
              </px-col>
              <px-col v-if="zhibiaostatus == '是'" :span="12">
                <px-form-item label="指标名称">
                  <px-input v-model="indicator.name" :maxlength="60" placeholder="请输入指标名称" clearable />
                </px-form-item>
              </px-col>
              <px-col v-if="zhibiaostatus == '是'" :span="12">
                <px-form-item label="监控周期" prop="cycle">
                  <px-select v-model="indicator.cycle" placeholder="请选择监控周期" clearable style="width: calc(100% - 70px)" filterable>
                    <px-option v-for="dict in cycleList" :key="dict.name" :label="dict.name" :value="dict.value" />
                  </px-select>
                </px-form-item>
              </px-col>
              <px-col v-if="zhibiaostatus == '是'" :span="12">
                <px-form-item label="执行时间" style="width: calc(100% - 70px)" prop="dateRange">
                  <px-date-picker
                    v-model="indicator.dateRange"
                    type="daterange"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                    format="YYYY-MM-DD"
                    value-format="YYYY-MM-DD"
                    :default-time="defaultTime"
                  />
                </px-form-item>
              </px-col>
              <px-col v-if="zhibiaostatus == '是'" :span="12">
                <px-form-item label="限值方式" prop="limitMethod">
                  <px-radio-group v-model="indicator.limitMethod" class="ml-4">
                    <px-radio label="百分比" size="large">百分比</px-radio>
                    <px-radio label="数值" size="large">数值</px-radio>
                  </px-radio-group>
                </px-form-item>
              </px-col>
              <px-col v-if="indicator.limitMethod == '百分比' && zhibiaostatus == '是'" :span="12">
                <px-form-item label="限值百分比" prop="limitValue">
                  <px-input-number
                    v-model="indicator.limitValue"
                    :min="0"
                    :max="99999.99999"
                    controls-position="right"
                    :precision="2"
                    style="width: calc(100% - 70px)"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
              <px-col v-if="indicator.limitMethod == '数值' && zhibiaostatus == '是'" :span="12">
                <px-form-item label="限值数值">
                  <px-input-number
                    v-model="indicator.limitMin"
                    controls-position="right"
                    :min="0"
                    :max="99999.99999"
                    style="width: calc(50% - 60px)"
                    placeholder="请输入"
                    clearable
                  />
                  <span style="margin: 0 5px">~</span>
                  <px-input-number
                    v-model="indicator.limitMax"
                    controls-position="right"
                    :min="0"
                    :max="99999.99999"
                    style="width: calc(50% - 60px)"
                    placeholder="请输入"
                    clearable
                  />
                </px-form-item>
              </px-col>
            </px-row>
          </div>
        </div>
      </px-form>
    </px-scrollbar>
    <px-scrollbar v-if="detailVisible" class="editorEquip">
      <px-button style="margin-left: 24px" type="primary" :icon="ArrowLeft" @click="equipopenDetailcancel2">返回</px-button>
      <div class="px-descriptions__title" style="margin: 20px 0 0 20px">基本信息</div>
      <px-descriptions class="margin-top" style="padding: 20px" title="" :column="2" border>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">设施/活动名称</div>
          </template>
          {{ equipdata.name }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">设施活动编号</div>
          </template>
          {{ equipdata.serialNumber }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">设施/活动类别</div>
          </template>
          {{ equipdata.category }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">活动水平单位</div>
          </template>
          {{ equipdata.activityLevelUnit }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">关联能源数据</div>
          </template>
          {{ equipdata.relatedEnergyname }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放因子名称</div>
          </template>
          {{ equipdata.emissionFactorName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放因子发布年份</div>
          </template>
          {{ equipdata.releaseYear }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放因子数值</div>
          </template>
          {{ equipdata.value }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放因子单位</div>
          </template>
          {{ equipdata.unit }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放因子来源</div>
          </template>
          {{ equipdata.factorSource }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">单位转换比例</div>
          </template>
          {{ equipdata.unitConversionRatio }}
        </px-descriptions-item>
        <!-- <px-descriptions-item>
          <template #label>
            <div class="cell-item">排放类别</div>
          </template>
          {{ equipdata.emissionCategory }}
        </px-descriptions-item> -->
        <!-- <px-descriptions-item>
          <template #label>
            <div class="cell-item">所属厂区</div>
          </template>
          {{ equipdata.level }}
        </px-descriptions-item> -->
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建人</div>
          </template>
          {{ equipdata.createByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建时间</div>
          </template>
          {{ equipdata.createTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改人</div>
          </template>
          {{ equipdata.updateByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改时间</div>
          </template>
          {{ equipdata.updateTime }}
        </px-descriptions-item>
      </px-descriptions>
      <div class="px-descriptions__title" style="margin: 20px 0 0 20px">碳排放源月平均排放标准值设置</div>
      <px-descriptions class="margin-top" style="padding: 20px" title="" :column="2" border>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">目标值（tCO₂e）</div>
          </template>
          {{ equipdata.targetValue }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">标杆值（tCO₂e）</div>
          </template>
          {{ equipdata.benchmarkValue }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">合规值（tCO₂e）</div>
          </template>
          {{ equipdata.complianceValue }}
        </px-descriptions-item>
      </px-descriptions>
      <div v-if="equipdata.indicator != null" class="px-descriptions__title" style="margin: 20px 0 0 20px">指标信息</div>
      <px-descriptions v-if="equipdata.indicator != null" class="margin-top" style="padding: 20px" title="" :column="2" border>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">指标名称</div>
          </template>
          {{ equipdata.indicator?.name }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">监控周期</div>
          </template>
          {{ equipdata.indicator?.cycle }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">执行时间</div>
          </template>
          {{ equipdata.indicator?.startTime }}-{{ equipdata.indicator?.endTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">限值方式</div>
          </template>
          {{ equipdata.indicator?.limitMethod }}
        </px-descriptions-item>
        <px-descriptions-item v-if="equipdata.indicator?.limitMethod == '百分比'">
          <template #label>
            <div class="cell-item">限值方式</div>
          </template>
          {{ equipdata.indicator?.limitValue }}%
        </px-descriptions-item>
        <px-descriptions-item v-if="equipdata.indicator?.limitMethod == '数值'">
          <template #label>
            <div class="cell-item">限值方式</div>
          </template>
          {{ equipdata.indicator?.limitMin }}-{{ equipdata.indicator?.limitMax }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建人</div>
          </template>
          {{ equipdata.indicator?.createByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">创建时间</div>
          </template>
          {{ equipdata.indicator?.createTime }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改人</div>
          </template>
          {{ equipdata.indicator?.updateByName }}
        </px-descriptions-item>
        <px-descriptions-item>
          <template #label>
            <div class="cell-item">修改时间</div>
          </template>
          {{ equipdata.indicator?.createTime }}
        </px-descriptions-item>
      </px-descriptions>
    </px-scrollbar>
    <div v-if="addVisible" class="px-dialog-footer">
      <px-button @click="equipopenDetailcancel">取消</px-button>
      <px-button type="primary" @click="equipopenDetailsubmitForm(detailruleFormRef)">保存</px-button>
    </div>
  </div>
</template>

<script setup name="Dict" lang="ts">
defineOptions({
  name: "SystemDataDict"
});
// import { router } from "@/router";
import { ArrowLeft } from "@px-ui/icons-vue";
import { useRouter } from "vue-router";
import { PxMessage, PxMessageBox } from "px-ui";
import { getCurrentInstance, ref, toRefs, reactive, onMounted } from "vue";
import { getToken } from "@/utils/auth";
import { queryChildByTypeCodeAndItemValue, dictItemqueryListByTypeCode } from "@/api/waterClass";
import {
  facilityquery,
  facilitysave,
  facilitydelete,
  facilitydetail,
  facilityedit,
  facilityUnitConvert
} from "@/api/doubleCarbonManage/accountingList";
import { emissionFactorquery, facilityuploadFile } from "@/api/doubleCarbonManage/carbonAccounting";
import importFiles from "./importFiles.vue";
const router = useRouter();
const jibenxinxiFlg = ref(true);
const jiqicanshuFlg = ref(true);
const zhibiaoFlg = ref(true);
const zhibiaostatus = ref("否");
const setqingdanFlg = () => {
  jibenxinxiFlg.value = !jibenxinxiFlg.value;
};
const setzhibiaoFlg = () => {
  zhibiaoFlg.value = !zhibiaoFlg.value;
};
const setjiqicanshuFlg = () => {
  jiqicanshuFlg.value = !jiqicanshuFlg.value;
};
const defaultTime: [Date, Date] = [new Date(2000, 1, 1, 0, 0, 1), new Date(2000, 1, 1, 23, 59, 59)];
const detailruleFormRef = ref();
const addchukuList = () => {
  progressVisible.value = true;
  queryParams2.value.dictWasteCode = "";
  getRukuList();
};
const dialogVisible = ref(false);
let facDisabled = ref(false);
onMounted(() => {
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      facDisabled.value = true;
      queryParams.value.level = faclist[0].name;
      getList();
    } else if (faclist.length == 2) {
      queryParams.value.level = faclist.filter(item => item.code == localStorage.getItem("facCode"))[0].name;
      getList();
    }
  }
});
const handleFileBrowsedetail = row => {
  if (row != null) {
    const { id, fileName, moduleName, fileType: type = "" } = row;
    // doc 暂不支持预览
    const allowType = ["txt", "docx", "xls", "xlsx", "pdf", "png", "jpg", "jpeg", "mp4"];
    if (!allowType.includes(type)) {
      PxMessage.error("暂不支持该格式文件的预览");
      return;
    }
    const path = "/fullScreen/preview";
    const query = { id, fileName, moduleName, type };
    const params = { path, query };
    const { href } = router.resolve(params);
    window.open(href, "_blank");
  } else {
    PxMessage.error("没有可以预览的文件");
  }
};
const defaultProps = {
  children: "children",
  label: "name",
  value: "value"
};
const { proxy }: any = getCurrentInstance();
function equipopenDetailcancel() {
  console.log(buttonTitle.value);
  if (buttonTitle.value == "新增") {
    if (
      equipdata.value.name != "" ||
      equipdata.value.serialNumber != "" ||
      equipdata.value.category != "" ||
      equipdata.value.relatedEnergy != "" ||
      equipdata.value.emissionFactorId != "" ||
      equipdata.value.emissionFactorName != "" ||
      equipdata.value.unit != "" ||
      equipdata.value.factorSource != "" ||
      equipdata.value.activityLevelUnit != "" ||
      equipdata.value.unitConversionRatio != null ||
      // equipdata.value.emissionCategory != "" ||
      equipdata.value.releaseYear != null ||
      equipdata.value.value != null ||
      equipdata.value.level != "" ||
      equipdata.value.targetValue != null ||
      equipdata.value.benchmarkValue != null ||
      equipdata.value.complianceValue != null
    ) {
      PxMessageBox.confirm("<p>取消将不保存当前录入信息返回上一页</p><p>确定取消吗？</p>", "温馨提示", {
        dangerouslyUseHTMLString: true,
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        draggable: true
      })
        .then(async () => {
          addVisible.value = false;
          getList();
        })
        .catch(() => {});
    } else {
      addVisible.value = false;
      getList();
    }
  } else {
    addVisible.value = false;
    getList();
  }
}
const equipopenDetailcancel2 = () => {
  detailVisible.value = false;
  getList();
};
const typeList = ref([]);
const progressVisible = ref(false);
const equipopen = ref(false);
const equipopenDetail = ref(false);
const fromdisable = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const addVisible = ref(false);
const detailVisible = ref(false);
const innerVisible = ref(false);
const total = ref(0);
const total2 = ref(0);
const dateRange = ref([]);

// 图片是否上传完，是否可以保存
const buttonTitle = ref("");
const data = reactive({
  codeList: [],
  facList: [], // 厂区下拉框
  liquidList: [],
  rukuList: [],
  transportCompanyList: [],
  receiveCompanyList: [],
  typeIdList: [],
  categoryList: [],
  equipmentTypeList: [],
  positionList: [],
  selectRukuList: {},
  okselectRukuList: [],
  equipmentDeptList: [],
  modelIdList: [],
  form: {},
  wasteUnitoptions: [
    {
      value: "克",
      label: "克"
    },
    {
      value: "千克",
      label: "千克"
    },
    {
      value: "吨",
      label: "吨"
    }
  ],
  photoStatusFlag: false,
  fileStatusFlag: false,
  equipdata: {
    id: "",
    name: "",
    serialNumber: "",
    category: "",
    relatedEnergy: "",
    emissionFactorId: "",
    emissionFactorName: "",
    unit: "",
    factorSource: "",
    activityLevelUnit: "",
    unitConversionRatio: null,
    // emissionCategory: "",
    standardValueList: {
      targetValue: "",
      benchmarkValue: "",
      complianceValue: ""
    },
    indicator: {},
    createByName: "",
    updateByName: "",
    releaseYear: "",
    value: "",
    facilityEmissionId: "",
    level: "",
    targetValue: null,
    benchmarkValue: null,
    complianceValue: null
  },
  indicator: {
    id: "",
    name: "",
    level: "",
    cycle: "",
    startTime: "",
    endTime: "",
    limitMethod: "百分比",
    limitValue: "",
    limitMin: "",
    limitMax: "",
    code: "",
    codeName: "",
    operator1: "",
    coefficient: "",
    operator2: "",
    emissionFactorId: "",
    emissionFactorName: "",
    createTime: "",
    createByName: "",
    updateTime: "",
    updateByName: "",
    dateRange: []
  },
  queryParams: {
    orderByColumn: "",
    isAsc: "",
    name: "",
    category: "",
    emissionFactorName: "",
    orderBy: "",
    level: "",
    pageNum: 1,
    pageSize: 20
  },
  queryParams2: {
    orderByColumn: "",
    isAsc: "",
    emissionFactorName: "",
    factorSource: "",
    releaseYear: "",
    orderBy: "",
    pageNum: 1,
    pageSize: 20
  },
  rules: {
    name: [{ required: true, message: "不能为空", trigger: "blur" }],
    serialNumber: [{ required: true, message: "不能为空", trigger: "blur" }],
    category: [{ required: true, message: "不能为空", trigger: "change" }],
    activityLevelUnit: [{ required: true, message: "不能为空", trigger: "change" }],
    emissionFactorName: [{ required: true, message: "不能为空", trigger: "blur" }],
    value: [{ required: true, message: "不能为空", trigger: "blur" }],
    factorSource: [{ required: true, message: "不能为空", trigger: "blur" }],
    releaseYear: [{ required: true, message: "不能为空", trigger: "blur" }],
    unit: [{ required: true, message: "不能为空", trigger: "blur" }],
    unitConversionRatio: [{ required: true, message: "不能为空", trigger: "blur" }],
    // emissionCategory: [{ required: true, message: "不能为空", trigger: "change" }],
    level: [{ required: true, message: "不能为空", trigger: "change" }],
    targetValue: [{ required: true, message: "不能为空", trigger: "blur" }],
    benchmarkValue: [{ required: true, message: "不能为空", trigger: "blur" }],
    complianceValue: [{ required: true, message: "不能为空", trigger: "blur" }],
    relatedEnergy: [{ required: true, message: "不能为空", trigger: "change" }]
  },
  headers: {
    Authorization: "Bearer " + getToken().accessToken || ""
  },
  moduleName: "",
  dialogImageUrl: "",
  imageVisible: false,
  levelUnitList: [],
  energyList: [],
  categoryTypeList: [],
  SourceList: [],
  selectrow: null,
  cycleList: [
    {
      name: "年",
      value: "年"
    },
    {
      name: "月",
      value: "月"
    },
    {
      name: "日",
      value: "日"
    }
  ],
  facList2: []
});
const selectyinzi = () => {
  getRukuList();
  innerVisible.value = true;
};

const {
  codeList,
  cycleList,
  indicator,
  liquidList,
  selectRukuList,
  queryParams,
  SourceList,
  levelUnitList,
  energyList,
  categoryTypeList,
  queryParams2,
  form,
  rules,
  equipdata,
  rukuList,
  selectrow,
  facList,
  facList2
} = toRefs(data);
const submitHandler = value => {
  getList();
};
const getqueryCategoryList = () => {
  dictItemqueryListByTypeCode({
    typeCode: "BICARBON_INDEX"
  }).then((response: any) => {
    console.log(response);
    codeList.value = response;
  });
  queryChildByTypeCodeAndItemValue({
    value: "EMISSION_FACTOR_SOURCE",
    typeCode: "BICARBON"
  }).then((response: any) => {
    SourceList.value = response;
  });
  facList.value = [
    {
      itemName: "全厂",
      itemValue: null
    },
    {
      itemName: "创新中心一期",
      itemValue: "创新中心一期"
    },
    {
      itemName: "创新中心二期",
      itemValue: "创新中心二期"
    }
  ];
  facList2.value = [
    {
      itemName: "创新中心一期",
      itemValue: "创新中心一期"
    },
    {
      itemName: "创新中心二期",
      itemValue: "创新中心二期"
    }
  ];
  //设施活动类别
  queryChildByTypeCodeAndItemValue({
    value: "FACILITY_CATEGORY",
    typeCode: "BICARBON"
  }).then((response: any) => {
    //console.log(response);
    liquidList.value = response;
  });
  //活动水平单位
  queryChildByTypeCodeAndItemValue({
    value: "ACTIVITY_LEVEL_UNIT",
    typeCode: "BICARBON"
  }).then((response: any) => {
    //console.log(response);
    levelUnitList.value = response;
  });
  //关联能源数据
  queryChildByTypeCodeAndItemValue({
    value: "RELATED_ENERGY",
    typeCode: "BICARBON"
  }).then((response: any) => {
    //console.log(response);
    energyList.value = response;
  });
  //排放类别
  dictItemqueryListByTypeCode({
    value: "EMISSION_CATEGORY",
    typeCode: "BICARBON"
  }).then((response: any) => {
    //console.log(response);
    categoryTypeList.value = response;
  });
};
const handledelAddPosition = () => {
  equipdata.value.standardValueList.unshift({
    level: "",
    targetValue: null,
    benchmarkValue: null,
    complianceValue: null
  });
};
const handelRadio = row => {
  selectrow.value = row;
};
function handleDeleteceng(row) {
  PxMessageBox.confirm("是否确认删除？", "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
    draggable: true
  })
    .then(async () => {
      equipdata.value.standardValueList = equipdata.value.standardValueList.filter(item => item != row);
      PxMessage({
        message: "删除成功",
        type: "success"
      });
      getList();
    })
    .catch(() => {});
}
const addsave = () => {};
getqueryCategoryList();
function getRukuList() {
  selectrow.value = null;
  loading.value = true;

  emissionFactorquery(queryParams2.value).then((response: any) => {
    rukuList.value = response.data;
    total2.value = response.total;
    loading.value = false;
  });
}

function getList() {
  loading.value = true;
  facilityquery(queryParams.value).then((response: any) => {
    typeList.value = response.data;
    total.value = response.total;
    loading.value = false;
  });
}
const removechukuList = () => {
  localStorage.removeItem("chukuList");
};
/** 取消按钮 */

/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    dictionaryName: undefined,
    dictionaryType: undefined,
    status: "VALID",
    remarks: undefined
  };
  proxy.resetForm("dictRef");
}
/** 搜索按钮操作 */
function handleQuery(type) {
  if (type == "search") {
    queryParams.value.pageNum = 1;
  }
  getList();
}
function handleQuery2(type) {
  if (type == "search") {
    queryParams2.value.pageNum = 1;
  }
  getRukuList();
}
/** 重置按钮操作 */
function resetQuery() {
  queryParams.value = {
    orderByColumn: "",
    isAsc: "",
    name: "",
    category: "",
    emissionFactorName: "",
    orderBy: "",
    level: "",
    pageNum: 1,
    pageSize: 20
  };
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      queryParams.value.level = faclist[0].name;
    } else if (faclist.length == 2) {
      queryParams.value.level = faclist.filter(item => item.code == localStorage.getItem("facCode"))[0].name;
    }
  }
  dateRange.value = [];
  handleQuery("reset");
}

function resetQuery2() {
  queryParams2.value = {
    pageNum: queryParams2.value.pageNum,
    pageSize: queryParams2.value.pageSize,
    orderByColumn: "",
    isAsc: "",
    dictWasteCode: "",
    startTime: "",
    endTime: "",
    status: "",
    orderBy: "",
    excludeInboundNumber: []
  };
  dateRange.value = [];
  handleQuery2("reset");
}

/** 新增按钮操作 */
function handleAdd() {
  buttonTitle.value = "新增";
  addVisible.value = true;
  equipdata.value = {
    name: "",
    serialNumber: "",
    category: "",
    relatedEnergy: "",
    emissionFactorId: "",
    emissionFactorName: "",
    unit: "",
    factorSource: "",
    activityLevelUnit: "",
    unitConversionRatio: null,
    // emissionCategory: "",
    standardValueList: {
      targetValue: "",
      benchmarkValue: "",
      complianceValue: ""
    },
    createByName: "",
    updateByName: "",
    facilityEmissionId: "",
    level: "",
    targetValue: null,
    benchmarkValue: null,
    complianceValue: null
  };
  if (localStorage.getItem("facList")) {
    let faclist = JSON.parse(localStorage.getItem("facList"));
    if (faclist.length == 1) {
      equipdata.value.level = faclist[0].name;
    } else if (faclist.length == 2) {
      equipdata.value.level = faclist.filter(item => item.code == localStorage.getItem("facCode"))[0].name;
    }
  }
  selectrow.value = null;

  indicator.value = {
    id: "",
    name: "",
    level: "",
    cycle: "",
    startTime: "",
    endTime: "",
    limitMethod: "百分比",
    limitValue: "",
    limitMin: "",
    limitMax: "",
    code: "",
    codeName: "",
    operator1: "",
    coefficient: "",
    operator2: "",
    emissionFactorId: "",
    emissionFactorName: "",
    createTime: "",
    createByName: "",
    updateTime: "",
    updateByName: "",
    dateRange: []
  };
}
const resetFrom = () => {
  detailruleFormRef.value.validateField("emissionFactorName");
  detailruleFormRef.value.validateField("value");
  detailruleFormRef.value.validateField("unit");
  detailruleFormRef.value.validateField("factorSource");
  detailruleFormRef.value.validateField("releaseYear");
};
const handleDetail = async val => {
  detailVisible.value = true;
  const data = await facilitydetail({ id: val });
  //console.log(data);

  equipdata.value = data;
  equipdata.value.targetValue = data.standardValue.targetValue;
  equipdata.value.benchmarkValue = data.standardValue.benchmarkValue;
  equipdata.value.complianceValue = data.standardValue.complianceValue;
};

const handleEditor = async val => {
  buttonTitle.value = "编辑";
  addVisible.value = true;
  const data = await facilitydetail({ id: val });
  //console.log(data);

  equipdata.value = data;
  if (data.indicator != null) {
    indicator.value = data.indicator;
    indicator.value.dateRange = [data.indicator.startTime, data.indicator.endTime];
    zhibiaostatus.value = "是";
  } else {
    zhibiaostatus.value = "否";
    indicator.value = {
      id: "",
      name: "",
      level: "",
      cycle: "",
      startTime: "",
      endTime: "",
      limitMethod: "百分比",
      limitValue: "",
      limitMin: "",
      limitMax: "",
      code: "",
      codeName: "",
      operator1: "",
      coefficient: "",
      operator2: "",
      emissionFactorId: "",
      emissionFactorName: "",
      createTime: "",
      createByName: "",
      updateTime: "",
      updateByName: "",
      dateRange: []
    };
  }
  equipdata.value.targetValue = data.standardValue.targetValue;
  equipdata.value.benchmarkValue = data.standardValue.benchmarkValue;
  equipdata.value.complianceValue = data.standardValue.complianceValue;
  selectrow.value = null;
};
/** 多选框选中数据 */
function handleSelectionChange2(selection) {
  console.log(selection);
  selectRukuList.value = selection;
}

// const addRukudetails = () => {
//   equipdata.value.details = [...equipdata.value.details, ...selectRukuList.value];
//   let seenIds = new Set();
//   let uniqueArr = [];
//   equipdata.value.details.forEach(obj => {
//     if (!seenIds.has(obj.inboundNumber)) {
//       uniqueArr.push(obj);
//       seenIds.add(obj.inboundNumber);
//     }
//   });
//   equipdata.value.details = [];
//   if (setChukuList(uniqueArr) == true) {
//     progressVisible.value = false;
//     equipdata.value.details = uniqueArr;
//   }
// };

let setChukuList = uniqueArr => {
  if (uniqueArr.length === 0) {
    PxMessage({
      message: "请选择要出库的数据",
      type: "error"
    });
    return false;
  }
  const firstname = uniqueArr[0].wasteName;
  for (let i = 1; i < uniqueArr.length; i++) {
    if (uniqueArr[i].wasteName != firstname) {
      PxMessage({
        message: "请选择相同的废弃物",
        type: "error"
      });
      return false;
    }
  }
  return true;
};

const handleDeleteRuku = row => {
  // console.log(row);
  equipdata.value.details = equipdata.value.details.filter(item => item != row);
};
const saveYinziku = () => {
  if (selectrow.value != null) {
    equipdata.value.emissionFactorId = selectrow.value.id;
    equipdata.value.emissionFactorName = selectrow.value.name;
    equipdata.value.value = selectrow.value.value;
    equipdata.value.unit = selectrow.value.unit;
    equipdata.value.factorSource = selectrow.value.factorSource;
    equipdata.value.releaseYear = selectrow.value.releaseYear;
    innerVisible.value = false;
    resetFrom();
    getUnitConvert(equipdata.value.activityLevelUnit, equipdata.value.unit);
  } else {
    PxMessage({
      message: `请选择排放因子`,
      type: "error"
    });
  }

  //selectrow
};
/**
 * 新增自动生成单位转换比例逻辑
 */
async function getUnitConvert(facilityLevelUnit: string, denominatorUnit: string) {
  if (!facilityLevelUnit || !denominatorUnit) return;
  const params = {
    facilityLevelUnit,
    denominatorUnit: denominatorUnit.split("/")[1]
  };
  const res: any = await facilityUnitConvert(params).catch(e => {
    console.warn(`output->e`, e);
    equipdata.value.unitConversionRatio = null;
  });
  if (res) {
    equipdata.value.unitConversionRatio = res;
  }
}
/** 提交按钮 */

const equipopenDetailsubmitForm = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate(async valid => {
    if (valid) {
      console.log(equipdata);
      const params = {
        name: equipdata.value.name,
        serialNumber: equipdata.value.serialNumber,
        category: equipdata.value.category,
        relatedEnergy: equipdata.value.relatedEnergy,
        emissionFactorId: equipdata.value.emissionFactorId,
        emissionFactorName: equipdata.value.emissionFactorName,
        unit: equipdata.value.unit,
        factorSource: equipdata.value.factorSource,
        activityLevelUnit: equipdata.value.activityLevelUnit,
        unitConversionRatio: equipdata.value.unitConversionRatio,
        // emissionCategory: equipdata.value.emissionCategory,
        level: equipdata.value.level,
        standardValue: {
          targetValue: equipdata.value.targetValue,
          benchmarkValue: equipdata.value.benchmarkValue,
          complianceValue: equipdata.value.complianceValue
        },
        createByName: JSON.parse(localStorage.getItem("userInfo")).username,
        updateByName: JSON.parse(localStorage.getItem("userInfo")).username,
        releaseYear: equipdata.value.releaseYear,
        value: equipdata.value.value,
        indicator: {}
      };
      if (buttonTitle.value == "新增") {
        console.log(zhibiaostatus.value);
        if (zhibiaostatus.value == "是") {
          params.indicator = {
            name: indicator.value.name,
            level: equipdata.value.level,
            cycle: indicator.value.cycle,
            startTime: indicator.value.dateRange[0] + " " + "00:00:00",
            endTime: indicator.value.dateRange[1] + " " + "23:59:59",
            limitMethod: indicator.value.limitMethod,
            limitValue: indicator.value.limitValue,
            limitMin: indicator.value.limitMin,
            limitMax: indicator.value.limitMax,
            emissionFactorId: equipdata.value.emissionFactorId,
            emissionFactorName: equipdata.value.emissionFactorName,
            code: equipdata.value.relatedEnergy,
            operator1: "×",
            coefficient: equipdata.value.unitConversionRatio,
            operator2: "×",
            createByName: JSON.parse(localStorage.getItem("userInfo")).username,
            updateByName: JSON.parse(localStorage.getItem("userInfo")).username
          };
          if (params.indicator.name == "") {
            PxMessage({
              message: `指标名称不能为空`,
              type: "error"
            });
            return false;
          }
          if (params.indicator.cycle == "") {
            PxMessage({
              message: `监控周期不能为空`,
              type: "error"
            });
            return false;
          }
          if (indicator.value.dateRange.length < 1) {
            PxMessage({
              message: `执行时间不能为空`,
              type: "error"
            });
            return false;
          }
          if (params.indicator.limitMethod == "百分比") {
            if (params.indicator.limitValue == "") {
              PxMessage({
                message: `限值百分比不能为空`,
                type: "error"
              });
              return false;
            }
          }
          if (params.indicator.limitMethod == "数值") {
            if (params.indicator.limitMax == "") {
              PxMessage({
                message: `数值不能为空`,
                type: "error"
              });
              return false;
            }
            if (params.indicator.limitMin == "") {
              PxMessage({
                message: `数值不能为空`,
                type: "error"
              });
              return false;
            }
          }
          facilitysave(params).then((response: any) => {
            PxMessage({
              message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
              type: "success"
            });
            resetQuery();
            addVisible.value = false;
          });
          getList();
        } else {
          params.indicator = {};
          facilitysave(params).then((response: any) => {
            PxMessage({
              message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
              type: "success"
            });
            resetQuery();
            addVisible.value = false;
          });
          getList();
        }
      } else {
        const params2 = {
          id: equipdata.value.id,
          name: equipdata.value.name,
          serialNumber: equipdata.value.serialNumber,
          category: equipdata.value.category,
          relatedEnergy: equipdata.value.relatedEnergy,
          emissionFactorId: equipdata.value.emissionFactorId,
          emissionFactorName: equipdata.value.emissionFactorName,
          unit: equipdata.value.unit,
          factorSource: equipdata.value.factorSource,
          activityLevelUnit: equipdata.value.activityLevelUnit,
          unitConversionRatio: equipdata.value.unitConversionRatio,
          // emissionCategory: equipdata.value.emissionCategory,
          level: equipdata.value.level,
          standardValue: {
            targetValue: equipdata.value.targetValue,
            benchmarkValue: equipdata.value.benchmarkValue,
            complianceValue: equipdata.value.complianceValue
          },
          indicator: {},
          updateByName: JSON.parse(localStorage.getItem("userInfo")).username,
          releaseYear: equipdata.value.releaseYear,
          value: equipdata.value.value,
          facilityEmissionId: equipdata.value.facilityEmissionId
        };
        if (zhibiaostatus.value == "是") {
          params2.indicator = {
            id: indicator.value.id,
            name: indicator.value.name,
            level: equipdata.value.level,
            cycle: indicator.value.cycle,
            startTime: indicator.value.dateRange[0] + " " + "00:00:00",
            endTime: indicator.value.dateRange[1] + " " + "23:59:59",
            limitMethod: indicator.value.limitMethod,
            limitValue: indicator.value.limitValue,
            limitMin: indicator.value.limitMin,
            limitMax: indicator.value.limitMax,
            emissionFactorId: equipdata.value.emissionFactorId,
            emissionFactorName: equipdata.value.emissionFactorName,
            code: equipdata.value.relatedEnergy,
            operator1: "×",
            coefficient: equipdata.value.unitConversionRatio,
            operator2: "×",
            createByName: equipdata.value.createByName,
            updateByName: JSON.parse(localStorage.getItem("userInfo")).username
          };
        } else {
          params2.indicator = null;
        }
        facilityedit(params2).then((response: any) => {
          PxMessage({
            message: `${buttonTitle.value == "新增" ? "添加成功" : "修改成功"}`,
            type: "success"
          });
          resetQuery();
          addVisible.value = false;
        });
        getList();
      }
    }
  });
};
/** 删除按钮操作 */
function handleDelete(row) {
  PxMessageBox.confirm("是否确认删除？", "温馨提示", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    confirmButtonClass: "px-button--danger",
    type: "warning",
    draggable: true
  })
    .then(async () => {
      const data = await facilitydelete({ id: row.id });
      PxMessage({
        message: "删除成功",
        type: "success"
      });
      getList();
    })
    .catch(() => {});
}

/** 导出按钮操作 */
const handleDown = async (reportId, templateIdval) => {
  proxy.download("post", "/energy/api/v1/facility/downloadTemplate", {}, "排放因子导入模板.xlsx");
};

/** 导入按钮操作 */
function handleImport() {
  // const dictIds = [];
  // dictIds.push(...ids.value);
  // const params = { ids: dictIds };
  // proxy.download("post", "/operation/api/v1/water/hazardWasteOut/export", params, "危险废弃物出库.xlsx");
  dialogVisible.value = true;
}
/** 导出按钮操作 */
function handleExport() {
  const params = {
    orderByColumn: queryParams2.value.orderByColumn,
    isAsc: queryParams2.value.isAsc,
    emissionFactorName: queryParams2.value.emissionFactorName,
    factorSource: queryParams2.value.factorSource,
    releaseYear: queryParams2.value.releaseYear,
    orderBy: queryParams2.value.orderBy
  };
  proxy.download("post", "/energy/api/v1/facility/export", params, "设施活动管理信息.xlsx");
  // const dictIds = [];
  // dictIds.push(...ids.value);
  // const params = { ids: dictIds };
  // proxy.download("post", "/operation/api/v1/water/hazardWasteOut/export", params, "危险废弃物出库.xlsx");
  // dialogVisible.value = true;
}
getList();
</script>
<style scoped lang="scss">
.addEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.editorEquip {
  position: absolute;
  top: 0;
  top: 5px;
  left: 0;
  width: calc(100% - 48px);
  height: calc(100% - 40px);
  margin: 24px;
  background: white;
}

.px-dialog-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: 2002;
  width: 100%;
  height: 50px;
  padding-top: 10px;
  padding-right: 34px;
  text-align: right;
  background: white;
  box-shadow: 0 0 10px 0 rgb(0 0 0 / 16%);
}

.card-header {
  min-height: 40px;
  padding: 14px 15px 7px !important;
  cursor: pointer;
  user-select: none;
  background: #e7eefb;
}

.card-title {
  float: left;
  font-size: 16px;
  font-weight: 600;
  line-height: 16px;
  color: rgb(0 0 0 / 80%);
}

.card-main {
  float: left;
  margin: -3px 8px 0 5px;
  cursor: pointer;
}

.box-card1 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card2 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card3 {
  width: calc(100% - 48px);
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.box-card4 {
  width: calc(100% - 48px);
  height: 261px;
  margin: 24px;
  overflow: hidden;
  border: 1px solid #dfdfdf;
  border-radius: 4px;
}

.demo-form-inline {
  .px-input {
    --px-input-width: calc(100% - 70px);
  }

  .px-form-item {
    width: 100%;
  }

  .px-textarea__inner {
    width: calc(100% - 100px) !important;
  }

  .px-form-item__label {
    font-weight: 400 !important;
  }
}

.form-div {
  padding: 24px;
  padding-bottom: 0;

  .px-row {
    margin-bottom: 5px;
  }
}

.px-icon {
  font-size: 16px !important;
}

:deep(.px-tabs--top .px-tabs__item.is-top.is-active) {
  border: none;

  .pane-bottom {
    line-height: 30px;
    border-bottom: 2px solid #3b82f6;
  }
}

:deep(.px-tabs .px-tabs__item) {
  .pane-bottom {
    line-height: 30px;
  }
}

.pane-line {
  position: absolute;
  top: 12px;
  right: 0;
  height: 15px;
  color: #dcdcdc;
  border-left: 1px solid #dcdcdc;
}

:deep(.custom-form-ui .px-form-item) {
  width: 250px !important;
}

.filename {
  position: absolute;
  bottom: -30px;
  width: 96px;
  overflow: hidden;
  color: rgb(166 167 172);
  text-overflow: ellipsis;
  white-space: nowrap;
}

:deep(.px-descriptions__label.px-descriptions__cell.is-bordered-label) {
  width: 166px;
  background: #e7eefb;
  border: 1px solid #dfdfdf;
}

:deep(.px-descriptions__body .px-descriptions__table.is-bordered .px-descriptions__cell) {
  border: 1px solid #dfdfdf;
}

.cell-item {
  text-align: right;
}

:deep(.px-table__header) {
  thead {
    tr {
      background-color: #e7eefb !important;

      th {
        font-size: 13px;
        font-weight: bold;
        color: #000;
        background-color: #e7eefb !important;
      }
    }
  }
}

.form-table {
  :deep(.px-table__header) {
    thead {
      tr {
        background-color: #e7eefb !important;

        th {
          font-size: 13px;
          font-weight: bold;
          color: #000;
          background-color: #d9e9ff !important;
        }
      }
    }
  }
}

:deep(.px-table--isfixedHeader .px-table__header-wrapper .px-table-fixed-column--right) {
  background-color: #e7eefb !important;
}

:deep(.px-input-number .px-input__inner) {
  text-align: left;
}

:deep(.px-input-number.is-controls-right .px-input__wrapper) {
  padding-left: 8px;
}

:deep(.px-input.is-disabled .px-input__wrapper) {
  background-color: white !important;
}

:deep(.px-input.is-disabled .px-input__inner) {
  color: #000 !important;
  -webkit-text-fill-color: #000 !important;
}

.import-bottle {
  .import-bottle-title {
    box-sizing: border-box;
    display: flex;
    align-items: center;
    width: 100%;
    height: 40px;
    padding-left: 16px;
    margin-bottom: 24px;
    line-height: 1;
    color: #333;
    background-color: #fef5e6;
    border: 1px solid #f7b648;
    border-radius: 6px;

    .download {
      color: #3b82f6;
      cursor: pointer;
    }
  }

  .import-bottle-upload {
    width: 100%;
  }
}
</style>
